﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using RemoteDesktops.Classes;

namespace RemoteDesktops.Dialogs
{
  /// <summary>
  /// Interaction logic for AddDesktop.xaml
  /// </summary>
  public partial class AddDesktop : Window
  {
    public AddDesktop()
    {
      InitializeComponent();
    }

    /// <summary>
    /// 
    /// </summary>
    public String Alias
    {
      get;
      set;
    }

    /// <summary>
    /// 
    /// </summary>
    public String ServerName
    {
      get;
      set;
    }

    /// <summary>
    /// 
    /// </summary>
    public String Description
    {
      get;
      set;
    }
    
    /// <summary>
    /// 
    /// </summary>
    public bool Add
    {
      get;
      set;
    }

    /// <summary>
    /// Accessort to DesktopList
    /// </summary>
    public Desktops DesktopList
    {
      get;
      set;
    }

    /// <summary>
    /// Ok Button Click
    /// </summary>
    /// <param name="sender">Sender Param</param>
    /// <param name="e">Routed Event Arg</param>
    private void OkButton_Click(object sender, RoutedEventArgs e)
    {
      if (this.DesktopList.Find(TBAlias.Text.Trim()) != null)
      {
        MessageBox.Show("Desktop with this Alias already Exists, please specify a different Alias", "Same Alias", MessageBoxButton.OK, MessageBoxImage.Error);
        TBAlias.Focus();        
      }
      else
      {
        this.Add = true;
        if (TBAlias.Text.Trim().Length > 0 && TBServerName.Text.Trim().Length > 0)
        {
          this.Alias = TBAlias.Text.Trim();
          this.ServerName = TBServerName.Text.Trim();
          this.Description = TBDesc.Text.Trim();
          this.Close();
        }
        else
        {
          MessageBox.Show("You must provide both an Alias and a Server Name to add a Desktop", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
        }
      }
    }

    /// <summary>
    /// Cancel Button Click
    /// </summary>
    /// <param name="sender">Sender Param</param>
    /// <param name="e">Routed Event Arg</param>
    private void CancelButton_Click(object sender, RoutedEventArgs e)
    {
      this.Add = false;
      if (TBAlias.Text.Trim().Length > 0 || TBServerName.Text.Trim().Length > 0)
      {
        if (MessageBox.Show("Are you sure you want to cancel", "Cancel ?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
        {
          this.Close();
        }
      }
      else
        this.Close();
    }
  }
}
